const { baseUrl } = require("../../utils/util");

// pages/sign/sign.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    islogin:0,
    isactivity:0,
    result:'',
    otherid:'',
    user:{
      
    },
    activety:{

    },
    phone:'',
    password:'',
    fileList: [],
    
    array:'',
    aid:'', 
    show: false,
    enc:'',
  },
  shoushiqiandao(){
    var that=this
    wx.request({
      url: baseUrl+'/general',
      method:'POST',
      data:{
           uf:that.data.user.uf,
          _d:that.data.user._d,
          vc3:that.data.user.vc3,
          uid:that.data.user.UID,
          name:that.data.user.name,
          aid:that.data.aid,
          fid:that.data.fid,
      },
      success(res){
        wx.showToast({
          title: res.data,
        })
        console.log(res)
      }
    })

  },
  weizhiqiandao(){
    var that=this
    wx.request({
      url: baseUrl+'/location',
      method:'POST',
      data:{
           uf:that.data.user.uf,
          _d:that.data.user._d,
          vc3:that.data.user.vc3,
          uid:that.data.user.UID,
          name:that.data.user.name,
          aid:that.data.aid,
          fid:that.data.fid,
          address:'中国',
          lat:'23.437261',
          lon:'113.177473'
      },
      success(res){
        wx.showToast({
          title: res.data,
        })
        console.log(res)
      }
    })
  },
  afterRead(event) {



    // const { file } = event.detail;
    // // 当设置 mutiple 为 true 时, file 为数组格式，否则为对象格式
    // wx.uploadFile({
    //   url: 'https://example.weixin.qq.com/upload', // 仅为示例，非真实的接口地址
    //   filePath: file.url,
    //   name: 'file',
    //   formData: { user: 'test' },
    //   success(res) {
    //     // 上传完成需要更新 fileList
    //     const { fileList = [] } = this.data;
    //     fileList.push({ ...file, url: res.data });
    //     this.setData({ fileList });
    //   },
    // });
  },
  scanCode:function(){
    var that=this;
    wx.scanCode({
      success(res){
        console.log(res)
        that.setData({
          enc:res.result.slice(-32)
        })
        console.log(res.result)
        console.log('---that.data.enc',that.data.enc)
      }
    })
     
  },
   getlogin:function(){
    // console.log("0-----------------")
    var that =this
    wx.request({
      url: baseUrl+'/login',
      method:'POST',
      data:{
        phone:this.data.phone,
        password:this.data.password
      },
      success(res){
       console.log("res",res)
       console.log("resdata.data",res.data)
        that.setData({
        user:res.data,
        islogin:1,
       })
       console.log("---",that.data.user)
      },
      error(e){
        console.log("ee",e)
      }
    })
  
  },
  getActivety:function(){
    var that =this
    wx.request({
      url: baseUrl+'/activity',
      method:'POST',
      data:{
        uf:that.data.user.uf,
        _d:that.data.user._d,
        vc3:that.data.user.vc3,
        uid:that.data.user.UID,
      },
      success(res){
        console.log("avtivetyres"+JSON.stringify(res))
        that.setData({
          activety:res,
          isactivity:1
        })
        console.log("activety",that.data.activety)
      }
    })
  },

 
  signUP:function(){
    var that =this;
      if (that.data.enc==='') {
        wx.showToast({
          title: '拍照内容为空',
          icon:'error'
        })
        return
      }
   
      wx.request({
        url: baseUrl+'/qrcode',
        method:'POST',
        data:{
          uf:that.data.user.uf,
          _d:that.data.user._d,
          vc3:that.data.user.vc3,
          uid:that.data.user.UID,
          name:that.data.user.name,
          aid:that.data.aid,
          fid:that.data.fid,
          enc:that.data.enc
        },
        success(res){
         that.setData({
            result:res.data
          })
          wx.showToast({
            title: res.data,
          })
          console.log("res",res)
        }
      })
  },
  showPopup() {
    this.setData({ show: true });
  },

  onClose() {
    this.setData({ show: false });
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
   console.log(options)
      this.setData({
        aid:options.code,
        otherid:options.otherid,
        user:wx.getStorageSync('signup')
      })
    console.log("signup",this.data.user)
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    // loginAgain()
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})